#ifndef __BASIC_PLATFORM_H__
#define __BASIC_PLATFORM_H__

#if defined(__WINDOWS__) || defined(_WIN32) || defined(WIN32) ||               \
    defined(_WIN64) || defined(WIN64) || defined(__WIN32__) ||                 \
    defined(__TOS_WIN__)
#define DK_PLATFORM_OS_NAME "windows"
#define DK_PLATFORM_OS_WINDOWS
#include <windows.h>
#elif defined(__linux__) || defined(linux) || defined(__linux) ||              \
    defined(__LINUX__) || defined(LINUX) || defined(_LINUX)
#define DK_PLATFORM_OS_NAME "linux"
#define DK_PLATFORM_OS_LINUX
#elif defined(__ANDROID__)
#define DK_PLATFORM_OS_NAME "android"
#define DK_PLATFORM_OS_ANDROID
#elif defined(__APPLE__) && defined(__MACH__)
#define DK_PLATFORM_OS_APPLE
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
#define DK_PLATFORM_OS_NAME "ios"
#elif TARGET_OS_TV
#define DK_PLATFORM_OS_NAME "tvos"
#else
#define DK_PLATFORM_OS_NAME "osx"
#endif
#else
#define DK_PLATFORM_OS_NAME "unknown"
#define DK_PLATFORM_OS_UNKNOWN
#error unknown os
#endif

#if defined(DK_PLATFORM_OS_WINDOWS)
#if defined(_WIN64)
#define DK_PLATFORM_ARCHITECTURE "x86_64"
#elif defined _WIN32
#define DK_PLATFORM_ARCHITECTURE "x86"
#endif
#elif defined(DK_PLATFORM_OS_ANDROID)
#if __arm__
#define DK_PLATFORM_ARCHITECTURE "armv7"
#elif __aarch64__
#define DK_PLATFORM_ARCHITECTURE "aarch64"
#endif
#elif defined(DK_PLATFORM_OS_LINUX)
#if __arm__
#define DK_PLATFORM_ARCHITECTURE "armv7"
#elif __aarch64__
#define DK_PLATFORM_ARCHITECTURE "aarch64"
#elif __i386__
#define DK_PLATFORM_ARCHITECTURE "x86"
#elif __x86_64__
#define DK_PLATFORM_ARCHITECTURE "x86_64"
#endif
#elif defined(DK_PLATFORM_OS_APPLE)
#if defined(__MACH__)
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE || TARGET_OS_TV
#if __LP64__
#define DK_PLATFORM_ARCHITECTURE "aarch64"
#else
#define DK_PLATFORM_ARCHITECTURE "armv7"
#endif
#endif
#else
#if __x86_64__
#define DK_PLATFORM_ARCHITECTURE "x86_64"
#elif __i386__
#define DK_PLATFORM_ARCHITECTURE "x86"
#endif
#endif
#else
#error "not supported architecture"
#endif

#if defined(_MSC_VER)
#define DK_PLATFORM_CC_NAME "vc"
#define DK_PLATFORM_CC_VC
#elif defined(__MINGW32__) || defined(__MINGW64__)
#define DK_PLATFORM_CC_NAME "mingw"
#define DK_PLATFORM_CC_MINGW
#elif defined(__GNUG__) || defined(__GNUC__)
#define DK_PLATFORM_CC_NAME "gcc"
#define DK_PLATFORM_CC_GCC
#else
#define DK_PLATFORM_CC_NAME "unknown"
#error unknown compiler
#endif

#ifndef M_API_FUNC
  #ifdef DK_PLATFORM_CC_VC
    #ifdef __cplusplus
      #ifdef DK3D_STATIC_LIB
        #define M_API_FUNC extern "C"
      #else
        #ifdef DK_SDK_EXPORTS
          #define M_API_FUNC __declspec(dllexport)
        #else
          #define M_API_FUNC __declspec(dllimport)
        #endif
      #endif
    #else
      #ifdef DK3D_STATIC_LIB
        #define M_API_FUNC
      #else
        #ifdef DK_SDK_EXPORTS
          #define M_API_FUNC __declspec(dllexport)
        #else
          #define M_API_FUNC __declspec(dllimport)
        #endif
      #endif
    #endif
  #else
    #ifdef __cplusplus
    #ifdef DK_SDK_EXPORTS
    #define M_API_FUNC
    //#           define M_API_FUNC extern "C"
    #else
    #define M_API_FUNC
    #endif
    #else
    #ifdef DK_SDK_EXPORTS
    #define M_API_FUNC __attribute__((visibility("default")))
    #else
    #define M_API_FUNC
    #endif
    #endif
  #endif
#endif

#define DK_PLATFORM_INFO                                                       \
  "OS:" DK_PLATFORM_OS_NAME ",  Compiler:" DK_PLATFORM_CC_NAME
//#define DK_PLATFORM_INFO "OS:" DK_PLATFORM_OS_NAME ", Bits:"
// DK_PLATFORM_BITS_NAME ", Compiler:" DK_PLATFORM_CC_NAME

#endif
